/**
 * 
 */
package com.googlecode.jasmincc.framework.services.implementation;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;

/**
 * @author Administrator
 * 
 */
public class SimpleFileSystemServices {
	protected String extName = null;

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.sourceforge.objectcc.services.FileSystemService#getFileByGrammarName(java.lang.String)
	 */
	public File getFileByGrammarName(String grammarName) throws FileNotFoundException {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.sourceforge.objectcc.services.FileSystemService#listFiles(java.lang.String)
	 */
	public File[] listFiles(File directory, String ext) {
		FilenameFilter filter = new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return name.endsWith(extName);
			}
		};

		return directory.listFiles(filter);
	}

	/**
	 * @return the extName
	 */
	public String getExtName() {
		return extName;
	}

	/**
	 * @param extName the extName to set
	 */
	public void setExtName(String extName) {
		this.extName = extName;
	}

	public static String getGrammarNameFromFile(File file) {
		String fileName = file.getName();
		int dot = fileName.lastIndexOf('.');
		String grammarName = fileName.substring(0, dot);
		return grammarName;
	}

}
